<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>TestPage Tests</title>
    <link rel="stylesheet" type="text/css" href="../css/jsUnitStyle.css">
    <script type="text/javascript" src="../app/jsUnitCore.js"></script>
    <script type="text/javascript" src="../app/jsUnitTestManager.js"></script>
    <script type="text/javascript" src="../app/BaseUiManager.js"></script>
    <script type="text/javascript" src="../app/ClassicUiManager.js"></script>
    <script type="text/javascript" src="../app/jsUnitParams.js"></script>
    <script type="text/javascript" src="../../My Notifier/jquery.js"></script>
    <script type="text/javascript" src="../../My Notifier/common.js"></script>
    <script type="text/javascript" src="../../My Notifier/main.js"></script>
	
    <script type="text/javascript">
		var ENV = "test";
		testSave();
		
		function simulatePost(url, data, callback){
			if(url.contains("extension-login.php")){
				asyncTestLogin(url, data, callback);
			} else if(url.contains("extension-set.php")) {
				asyncTestSave(url, data, callback);
			} else if(url.contains("extension-get.php")){
				asyncTestRetrieve(url, data, callback);
			} else if(url.contains("extension-get-timestamp.php")){
				if(localStorage.special == ""){
					asyncTestTimestamp(url, data, callback);
				} else if(localStorage.special == "2"){
					asyncTestTimestamp2(url, data, callback);
				} else if(localStorage.special == "3"){
					asyncTestTimestamp3(url, data, callback);
				}
			}
		}
	
	
        function testRemoveDynamicElement() {
			localStorage['elementList'] = "test|test1|test2";
			localStorage['test1-date'] = 'date';
			localStorage['test1-frequency'] = 'frequency';
			localStorage['test1-url'] = 'url';
			localStorage['test1-postit'] = 'postit';
			removeDynamicElement('elementList', 'test1');
			if(localStorage['test1-date'] || localStorage['test1-frequency'] || localStorage['test1-url'] || localStorage['test1-postit']){
				fail("Fais chier");
			}			
        }
		
		function asyncTestLogin(url, data, callback){
			callback('{"token": "tokentest"}');
		}
		
		function testLogin(){
			login("achatell", "msmsms");
			assertTrue(localStorage.token == "tokentest");
			assertTrue(localStorage.login == "achatell");
		}

		function asyncTestSave(url, data, callback){
			assertTrue(data['data'][0].name == 'timestamp');
			assertTrue(data['data'][1].name == 'elementList');
			assertTrue(data['data'][1].value == 'test');
			assertTrue(data['data'][2].name == 'test-date');
			assertTrue(data['data'][2].value == 'test');
			assertTrue(data['data'][3].name == 'test-frequency');
			assertTrue(data['data'][3].value == 'test');
			assertTrue(data['data'][4].name == 'test-url');
			assertTrue(data['data'][4].value == 'test');
			assertTrue(data['data'][5].name == 'test-postit');
			assertTrue(data['data'][5].value == 'test');
			callback("{}");
		}
		
		function testSave(){
			localStorage.reste = 'tata';
			localStorage.elementList = 'test';
			localStorage['test-date'] = 'test';
			localStorage['test-frequency'] = 'test';
			localStorage['test-url'] = 'test';
			localStorage['test-postit'] = 'test';
			saveConfiguration();
			assertTrue(localStorage.hasChanged == "0");
		}
		
		function asyncTestRetrieve(url, data, callback){
			callback('{"data": [{"name": "token", "value": "tokentest"}, {"name": "reste", "value": "titi"}, {"name": "testList", "value": "you|ye"}, {"name": "test2List", "value": "te|you|ye"}, {"name": "test3List", "value": "you|ye"}, {"name": "test4List", "value": ""}]}');
		}
		
		function testRetrieve(){
			localStorage.testList="te|you";
			localStorage.test2List="";
			localStorage.test3List="te";
			localStorage.test4List="te|you|ye";
			
			retrieveConfiguration();
			assertTrue(localStorage.token == "tokentest");
			assertTrue(localStorage.reste == "titi");
			assertTrue(localStorage.testList == "te|you|ye");
			assertTrue(localStorage.test2List == "te|you|ye");
			assertTrue(localStorage.test3List == "te|you|ye");
		}
		
		function asyncTestTimestamp(url, data, callback){
			callback('{"timestamp": "213"}');
		}
		
		function asyncTestTimestamp2(url, data, callback){
			callback('{"timestamp": "999999999999999"}');
		}
		
		function asyncTestTimestamp3(url, data, callback){
			callback('{}');
		}
		
		function testTimestamp(){
			localStorage.special = "";
			var callback = function(timestamp){
				assertTrue(timestamp == "213");
			}
			getTimestamp(callback);
		}
		
		
		function testSynchronize(){
			localStorage.timestamp = "1323";
			localStorage.special = "";
			synchronize();
			assertTrue(localStorage.synchro=="1");
			localStorage.special = "2";
			synchronize();
			assertTrue(localStorage.synchro=="0");
			localStorage.special = "3";
			synchronize();
			assertTrue(localStorage.synchro=="1");
			localStorage.removeItem('timestamp');
			synchronize();
			assertTrue(localStorage.synchro=="1");
			localStorage.special = "";
			localStorage.removeItem('timestamp');
			synchronize();
			assertTrue(localStorage.synchro=="0");
		}

		function testExtractNameFromUrl(){
			assertTrue(extractNameFromUrl("http://www.google.com/sdfdsf") == "Google");
			assertTrue(extractNameFromUrl("http://digg.com/baseball/College_Baseball_Teams_Go_Crazy_During_Rain_Delay_Video") == "Digg");
			assertTrue(extractNameFromUrl("http://www.javascripter.net/faq/convert2.htm") == "Javascripter");
			assertTrue(extractNameFromUrl("http://www.binnews.in/index.php?country=fr") == "Binnews");
			assertTrue(extractNameFromUrl("http://www.optioncarriere.com/wrecherche/emplois?s=java&l=gironde&lid=24133&sort=date") == "Optioncarriere");
		}
		
    </script>
</head>

<body>
    <h1>TestPage Tests</h1>
</body>
</html>
